package com.jichaoyun.model.vo;


import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 一天的数据
 */
@Data
@NoArgsConstructor
public class DayDataVo {
    private LocalDateTime date;

    //流速
    private float[] flow = new float[24];

    //压力
    private float[] pressure = new float[24];

    //温度
    private float[] temperature = new float[24];

    //频率
    private float[] frequency = new float[24];


    public DayDataVo(LocalDateTime day){
        this.date = day;
    }

    // 手动转换方法
    public String getDate2String() {
        return date.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    }

    public void setString2Date(String dateStr) {
        this.date = LocalDateTime.parse(dateStr, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    }

    public void setFlow(int index, float value) {
        if (index < 0 || index >= 24) {
            throw new IndexOutOfBoundsException();
        }
        this.flow[index] += value;
    }

    public void setPressure(int index, float value) {
        if (index < 0 || index >= 24) {
            throw new IndexOutOfBoundsException();
        }
        this.pressure[index] += value;
    }

    public void setTemperature(int index, float value) {
        if (index < 0 || index >= 24) {
            throw new IndexOutOfBoundsException();
        }
        this.temperature[index] += value;
    }

    public void setFrequency(int index, float value) {
        if (index < 0 || index >= 24) {
            throw new IndexOutOfBoundsException();
        }
        this.frequency[index] += value;
    }

}
